-module(sc_store).

-export([
    init/0,
    insert/2,
    delete/1,
    lookup/1
]).

-define(ETS_K2P, key_to_pid).

init() ->
    ets:new(?ETS_K2P, [public, named_table]),
    ok.

insert(Key, Pid) ->
    ets:insert(?ETS_K2P, {Key, Pid}).

lookup(Key) ->
    case ets:lookup(?ETS_K2P, Key) of 
        [{Key, Pid}] ->
            {ok, Pid};
        []-> {error, not_exist}
    end.

delete(Pid) ->
    ets:match_delete(?ETS_K2P, {'_', Pid}).